<?php $this->_extends('../_layouts/userbind_layout'); ?>

<?php $this->_block('contents'); ?>

<div id="getting-started">
<?php
// user_id, group_id, account, user_name, password, ipzone, email, mobile, phone, join_day, dimission_day, birthday,
// created, updated, is_locked, register_ip, last_login, last_login_ip, login_count
// group_id, parent_id, group_name, left_value, right_value, description, has_users
// role_id rolename description user_owned group_owned
//$show_box['user_info']
?>

<ul class="infolisti">
   <li>编　　号：<?php echo $show_box['user_info']['user_id'];?></li>
   <li>姓　　名：<?php echo $show_box['user_info']['user_name'];?></li>
   <li>登录帐号：<?php echo $show_box['user_info']['account'];?></li>
   <li>所 在 组：<?php echo $show_box['user_info']->group->group_name;?></li>
   <li style="display:none">拥有角色<?php echo $show_box['user_info']->group->group_name;?></li>
   <li style="display:none">是否锁定<?php echo $show_box['user_info']['is_locked']?'已锁定':'未锁定';?></li>
   <li>设置权限<div>
<form name="form_roleaddform" action="<?php echo url('admin::users/bind')?>" method="post" enctype="application/x-www-form-urlencoded" ><ul class="rightlist">
<?php
$form_elements = '';
$icut=false;$icutg=false;
//echo $show_box['user_info']->group->group_name;
if($show_box['user_info']->group->group_name=='普通用户')
	$icut=true;

if($show_box['user_info']->group->group_name=='主机管理员')
	$icut=false;

//dump($show_box['user_info']);

foreach ( $show_box['roles'] as $value){
  
	$icutg=false;
	if($icut && $value['rolename']!='GADMIN'){
		$icutg=true;
	}

	if(!$icut && $value['rolename']!='NORMAL'){
		$icutg=true;
	}

//	if($icut && $value['rolename']!='GADMIN'){
//		echo 'asdasd1';
//		$icut=true;
//	}else{
//		if(!$icut && $value['rolename']!='NORMAL'){
//			echo 'asdasd2';
//			$icut=true;
//		}else{
//			echo 'asdasd3';
//			$icut=false;
//		}
//	}
	 
	if($value['rolename']!='ADMIN' && $value['rolename']!='FREEZE' && $value['rolename']!='REPEAL' && $value['rolename']!='SYSADM' && $icutg){

	//$checked = in_array($value['role_id'],$show_box['user_roles']) ? ' checked="checked"':'';
    if ( in_array($value['role_id'],$show_box['user_roles']['role_id']) ){
        if ($show_box['user_roles'][$value['role_id']]){
            $form_elements .= '<li><input type="radio" id="role_id_'.$value['role_id'].'_1" name="role_id['.$value['role_id'].']" value="1" checked="checked"/><label for="role_id_'.$value['role_id'].'_1" style="font-weight:normal;"></label> ';
            //$form_elements .= '<input type="radio" name="role_id['.$value['role_id'].']" value="0" />deny';
        }else{
            $form_elements .= '<li><input type="radio" id="role_id_'.$value['role_id'].'_1" name="role_id['.$value['role_id'].']" value="1" checked="checked"/><label for="role_id_'.$value['role_id'].'_1" style="font-weight:normal;"></label> ';
			//$form_elements .= '<input type="radio" name="role_id['.$value['role_id'].']" value="1" />allow';
            //$form_elements .= '<input type="radio" name="role_id['.$value['role_id'].']" value="0" checked="checked"/>deny';
        }
        $form_elements .= '<input type="radio" style="display:none" id="role_id_'.$value['role_id'].'_2" name="role_id['.$value['role_id'].']" value="n" /><label style="display:none;font-weight:normal;" for="role_id_'.$value['role_id'].'_2">取消</label>'.$value['description'].'</li>';
    }else{
        $form_elements .= '<li><input type="radio" id="role_id_'.$value['role_id'].'_1" name="role_id['.$value['role_id'].']" value="1" /><label for="role_id_'.$value['role_id'].'_1" style="font-weight:normal;"></label> ';
        //$form_elements .= '<input type="radio" name="role_id['.$value['role_id'].']" value="0" />deny';
        $form_elements .= '<input type="radio" style="display:none" id="role_id_'.$value['role_id'].'_2" name="role_id['.$value['role_id'].']" value="n" checked="checked"/><label style="display:none;font-weight:normal;" for="role_id_'.$value['role_id'].'_2">取消</label>'.$value['description'].'</li>';
    }
    //$form_elements .= ' '.$value['role_id'].' '.$value['rolename'].' '.$value['description'].''."\n";

	}
}
echo $form_elements;
?>
    <li>
	<input type="submit" name="btn_submit" value="提交" class="btn" />
    <input type="hidden" name="user_id" id="user_id" value="<?php echo $show_box['user_info']['user_id'];?>" /></li>
	</ul>
</form>
</div></li>
</ul>

<?php //$this->_element('../../_elements/formview_simple', array('form' => $show_box['form'])); ?>
<?php //dump($show_box['user_roles']);?>
<?php //dump($show_box['roles']);?>

<?php $this->_endblock(); ?>